from functools import wraps

def require_role(role):
    """基于角色的权限检查"""
    def decorator(func):
        @wraps(func)
        def wrapper(user, *args, **kwargs):
            if user.get('role') != role:
                raise PermissionError(f"需要 {role} 权限，当前用户: {user.get('role')}")
            return func(user, *args, **kwargs)
        return wrapper
    return decorator

@require_role("admin")
def delete_user(user, user_id):
    return f"用户 {user_id} 已被删除"

user = {"name": "Alice", "role": "user"}
admin = {"name": "Bob", "role": "admin"}

try:
    print(delete_user(admin, 123))  # 成功
    print(delete_user(user, 456))   # 失败
except PermissionError as e:
    print(f"❌ 权限错误: {e}")